home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / libsurf / fog.c < prev    next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  73 lines

  1. /*
  2.  * fog.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: fog.c,v 4.0 91/07/17 14:40:14 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    fog.c,v $
  19.  * Revision 4.0  91/07/17  14:40:14  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "atmosphere.h"
  24. #include "fog.h"
  25.  
  26. Fog *
  27. FogCreate(color, trans)
  28. Color *color, *trans;
  29. {
  30.     Fog *fog;
  31.     static void ComputeFog();
  32.  
  33.     fog = (Fog *)Malloc(sizeof(Fog));
  34.  
  35.     if (color == (Color *)NULL)
  36.         fog->color.r = fog->color.g = fog->color.b = 0.;
  37.     else
  38.         fog->color = *color;
  39.     if (trans == (Color *)NULL)
  40.         fog->trans.r = fog->trans.g = fog->trans.b = FAR_AWAY;
  41.     else {
  42.         fog->trans = *trans;
  43.     }
  44.     return fog;
  45. }
  46.  
  47. /*
  48.  * Add fog to the given color.
  49.  */
  50. void
  51. FogApply(fog, ray, pos, dist, color)
  52. Fog *fog;
  53. Ray *ray;
  54. Vector *pos;
  55. Float dist;
  56. Color *color;
  57. {
  58.     Float atten;
  59.     extern Float ExpAtten();
  60.  
  61.     atten = ExpAtten(dist, fog->trans.r);
  62.     if (fog->trans.r == fog->trans.g && fog->trans.r == fog->trans.b) {
  63.         ColorBlend(color, &fog->color, atten, 1. - atten);
  64.         return;
  65.     }
  66.     color->r = atten*color->r + (1. - atten) * fog->color.r;
  67.  
  68.     atten = ExpAtten(dist, fog->trans.g);
  69.     color->g = atten*color->g + (1. - atten) * fog->color.g;
  70.     atten = ExpAtten(dist, fog->trans.b);
  71.     color->b = atten*color->b + (1. - atten) * fog->color.b;
  72. }
  73.